const app = getApp()
const utils = require('../../../utils/util.js')

// let baseUrl = 'https://crm.quanyou.com.cn/appweb/#/order/sign-up?token='
// let baseUrl = 'http://192.168.99.98:4200/#/wechat/order/sign-up?token='
// let baseUrl = ''
// let baseUrl = 'https://crmcs.quanyou.com.cn/appweb/#/order/sign-up?token='
// let baseUrl = 'http://192.168.99.167:4200/#/order/sign-up?token='
// let baseUrl = "https://qmpdev.quanyou.com.cn/top2-crm-register/registerPage"
let baseUrl = "https://mpanda.quanyou.com.cn/top2-crm-register/registerPage"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    src: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const phone = wx.getStorageSync('sharerPhone') || ''
    console.log(phone)
    utils.$http(app.globalData.api.getCrmTokenL, {}, "GET", false, "JSON").then(({ msg, success }) => {
      // console.log('toCrmPage:', app.globalData.toCrmPage)
      // ?sourceSystem=WechatFriendsTencent&showAddress=1&showSpace=1&sharingPeoplePhone=18202822318&token=
      const data = {
        sourceSystem: 'CaseShare',
        // showAddress: 1,
        showSpace: 1,
        sharingPeoplePhone: phone,
        token: msg
      }
      if (success === 1) {
        const webUrl = baseUrl +'?'+ this.serialize(data)
        // const webUrl = baseUrl + msg + '&phone=' + phone + '&thirdSource=CaseShare'
        console.log("webURL:",webUrl)
        this.setData({
          src: webUrl
        })
      }
    })
  },
/*
 *序列化query
 */
 serialize(data) {
    const list = []
    Object.keys(data).forEach(ele => {
      list.push(`${ele}=${data[ele]}`)
    })
    return list.join('&')
  },
  getCRMDesginBaseUrl(successCallBack = ()=>{}){
    utils.$http(app.globalData.api.getCRMDesginBaseUrl, {}, "GET", false, "JSON").then(({ data, success }) => {
      if (success === 1) {
        successCallBack(data)
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})